﻿using System;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;
using System.Web.UI;
using System.Data;
using ASPNETVN.PORTAL.Modules.GUIDE.Components;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using System.Web;
using ASPNETVN.PORTAL.Components.Share;
using System.Collections;
using System.Web.UI.WebControls;

namespace ASPNETVN.PORTAL.Modules.GUIDE
{
    public enum ModulePages
    {
        GuideContentManager,
        GuiderManager,
        AddEditItem,
        GuideAreaManager,
        GuideList,
        Detail
    }    

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            
            // Cách thức lưu trữ file upload.
            ArrayList listStorageType = new ArrayList();
            listStorageType.Add(new ListItem("Link", "LINK"));
            listStorageType.Add(new ListItem("File", "FILE"));
            listStorageType.Add(new ListItem("Database", "DATABASE"));

            ModuleSettingItem storageType = new ModuleSettingItem(new CustomListDataType(listStorageType, "Text", "Value"));
            storageType.Name = "Storage Type";
            storageType.Description = "Storage Type";
            storageType.SortOrder = 8;
            this.BaseSettings.Add("StorageType", storageType);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.GUIDE/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page;
            if (pageName == null)
            {
                page = ModulePages.GuideList;
            }
            else
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditItem");    
        }        

    }
}